#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>

#include <iostream>
#include <fstream>

#include "anora.h"

#include "Statistic.h"

#include "rapidxml-1.13/rapidxml.hpp"
#include "rapidxml-1.13/rapidxml_print.hpp"

#include "xmlloader.h"

#include "Character.h"

#define STR "1d20-1d3+2"

using namespace rapidxml;

void printstatlist( const std::string& listname, const StatList& list )
{
	std::cout << listname << ":" << std::endl;
	for( unsigned int i = 0; i < list.length(); ++i )
	{
		std::cout << "\t" << list[i].toString() << std::endl;
	}
	std::cout << std::endl;
}

int main()
{
	StatList statList1, statList2;
	//statList.set("Level", 5);

	statList1["Level"] = 5;
	statList1["Name"] = "Steve";

	printstatlist("statList1",statList1);

	++++statList2["Level"]+++++="hello";

	printstatlist("statList2",statList2);

	StatList statList3 = statList1+statList2;

	printstatlist("statList3",statList3);

	statList1["Name"] = "bob";

	printstatlist("statList1",statList1);

	statList3 += statList1;

	printstatlist("statList3",statList3);

	statList1["Experience"] = 100;
	statList1["Experience"] = "XP";

	printstatlist("statList1",statList1);

	statList2["Name"] = "Jergins";

	printstatlist("statList2.combine(statList1,1,1,' ')",statList2.combine( statList1, true, true, " " ));

	statList3 += statList2.combine( statList1, true, true, " " );

	printstatlist("statList3",statList3);


	Character character( "example_character_file.xml" );

	printstatlist("character",character);
	std::cout << (std::string)character["name"].parent()->operator[]("name") << std::endl;


	int lvltmp = statList3["Level"];
	printf("\nLevel = %d\n",lvltmp);

	srand( (unsigned) time( NULL ) );
	int min = 0, max = 0;
	long long int total = 0;
	unsigned int nd = 1;
	int t = 6, mod = 0;
	roll_dice_parse_str( STR, &nd, &t, &mod );
	for( unsigned long long int i = 0; i < (unsigned long long int)-1; ++i )
	{
		//int ret = roll_dice( nd, t, mod );
		int ret = roll_multidice_str( STR );
		total += ret;
		if( !i )
			min = max = ret;
		if( ret > max )
			max = ret;
		if( ret < min )
			min = ret;
		//if( !((i+1)%1000000) )
			printf( "roll_multidice_str(\"%s\"): %3d, min:%3d, max:%3d, avg:%8.4lf, %llu\n", STR, ret, min, max, double(total)/double(i+1), i+1 );
	}
	//printf( "roll_dice_str(\"%s\"): min:%d, max:%d\n", STR, min, max );
	return 0;
}